﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HNCDataSetTableAdapters;
public partial class UserControl_content_right : System.Web.UI.UserControl
{
    CategoryTableAdapter cate = new CategoryTableAdapter();
    ProductsTableAdapter pro = new ProductsTableAdapter();
    InfoTableAdapter info = new InfoTableAdapter();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadAbout();
            ltrTop4News.Text = loadNews();
            loadVideo();
            ltrService.Text = loadService();
        }
    }

    public void loadAbout()
    {
        DataTable dt = info.GetInfoByID(1);
        ltrDescription.Text = FuntionHNC.Catchuoi(dt.Rows[0]["Description"].ToString(), 200);
    }

    public string loadNews()
    {
        DataTable dt = pro.GetProductByCateIDTop(5, 4);
        string str = "";
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string ProductID = dt.Rows[i]["ProductID"].ToString();
            string Title = dt.Rows[i]["Title"].ToString();
            str += " <li><a href=\"chi-tiet-tin-tuc-du-an-" + ProductID + ".html\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + Title + "</a></li>";
        }
        return str;
    }

    public void loadVideo()
    {
        DataTable dt = pro.GetProductByCateIDTop(1, 6);
        rptVideo.DataSource = dt;
        rptVideo.DataBind();
    }

    public string loadService()
    {
        string str = "";
        DataTable dt = cate.GetCateByParentID(7);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                String Title = dt.Rows[i]["Title"].ToString();
                int CateID = int.Parse(dt.Rows[i]["CateID"].ToString());
                str += "<div><div class=\"ttd\">";
                str += Title + " &nbsp;&nbsp;<img src=\"images/ngoac.png\" width=\"16\" height=\"16\" /></div>";
                DataTable dt1 = pro.GetProductByCateIDTop(1, CateID);
                if (dt1.Rows.Count > 0)
                {
                    String ProductID = dt1.Rows[0]["ProductID"].ToString();
                    String Image = dt1.Rows[0]["Image"].ToString();
                    String title1 = dt1.Rows[0]["Title"].ToString();
                    //str += "</div>";
                    str += "<a title=\""+title1+"\" href=\"chi-tiet-tin-tuc-du-an-" + ProductID + ".html\">";
                    str += "<div class=\"ksp\">";
                    str += "<img class=\"imgk\" alt=\""+title1+"\" src=\"UserUploads/Product/" + Image + "\">";
                    str += "</div></a>";
                }
                str += "</div>";
            }      
        return str;
    }

}